package cn.edu.tju.wiki;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.tju.wiki.utils.GenJsonJsFile;

@SuppressWarnings("serial")
public class GetAndPostExample extends HttpServlet {

    protected void processRequest(HttpServletRequest request,
            HttpServletResponse response, String method)
            throws Exception {
		    	GenJsonJsFile.outputJsForChordMatrix();
                //����Ӧ������������Ϊ text/xml
                response.setContentType("text/xml");
                //�õ��û�����ֵ
                String firstName = request.getParameter("firstName");
                String middleName = request.getParameter("middleName");
                String birthday = request.getParameter("birthday");
               //��ɰ��û�����ֵ�ķ����ַ�
                String responseText = "Hello " + firstName + " " + middleName
                + ". Your birthday is " + birthday + "."
                + " [Method: " + method + "]";
                //д�������
                PrintWriter out = response.getWriter();
                out.println(responseText);
                out.close();
            }
            protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                //Get���������processRequest,���Get�����Ĳ�����ܣ����صĹ��
                try {
					processRequest(request, response, "GET");
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
            protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                //POST���������processRequest,���POST�����Ĳ�����ܣ����صĹ��
                try {
					processRequest(request, response, "POST");
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
            }
}
